package servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/main")
public class MainServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public MainServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		String method = request.getParameter("method");
		if(method != null){
			if(method.equals("showMission")){
				request.setAttribute("panel", "mission");
				request.getRequestDispatcher("main.jsp").forward(request, response);
			}
			if(method.equals("showWeibos")){
				request.setAttribute("panel", "weibos");
				request.getRequestDispatcher("main.jsp").forward(request, response);
			}
			if(method.equals("showUsers")){
				request.setAttribute("panel", "users");
				request.getRequestDispatcher("main.jsp").forward(request, response);
			}
			if (method.equals("showSimulation")) {
				request.setAttribute("panel", "weibos");
				request.getRequestDispatcher("simulation.jsp").forward(request,
						response);
			}
		}
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
